package com.gps.funnymath.main;

import java.util.ArrayList;

import com.gps.funnymath.abstractItems.AbstractToken;


public class AbstractProblem {

	// Sentence structure
	private ArrayList<AbstractToken> abstractData;
	private ArrayList<AbstractToken> abstractQuestion;
	private ArrayList<AbstractToken> abstractSolution;
	private ArrayList<AbstractToken> abstractEasyTip;
	
	public AbstractProblem(){
		abstractData = new ArrayList<AbstractToken>();
		abstractQuestion = new ArrayList<AbstractToken>();
		abstractSolution = new ArrayList<AbstractToken>();
		abstractEasyTip = new ArrayList<AbstractToken>();
	}

	ConcreteProblem instantiate(){

		ConcreteProblem concreteProblem = new ConcreteProblem();;
		
		// Problem Data
		for(AbstractToken abstractToken : abstractData){
				concreteProblem.addTokenToData(abstractToken.getConcreteToken());
		}
		
		// Problem Question
		for(AbstractToken abstractToken : abstractQuestion){
				concreteProblem.addTokenToQuestion(abstractToken.getConcreteToken());
		}
		
		// Problem Solution
		for(AbstractToken abstractToken : abstractSolution){
				concreteProblem.addTokenToSolution(abstractToken.getConcreteToken());
		}
		
		// Problem EasyTip
		for(AbstractToken abstractToken : abstractEasyTip){
				concreteProblem.addTokenToEasyTip(abstractToken.getConcreteToken());
		}

		clearInstantiationReferences();
		
		return concreteProblem;
	}
	
	
	boolean addTokenToData(AbstractToken abstractToken){
		return abstractData.add(abstractToken);
	}
	boolean addTokenToQuestion(AbstractToken abstractToken){
		return abstractQuestion.add(abstractToken);
	}
	boolean addTokenToSolution(AbstractToken abstractToken){
		return abstractSolution.add(abstractToken);
	}
	boolean addTokenToEasyTip(AbstractToken abstractToken){
		return abstractEasyTip.add(abstractToken);
	}
	
	void clearInstantiationReferences(){
		
		for(AbstractToken abstractToken : abstractData){
			abstractToken.clearInstantiationReferences();
		}
		
		// Problem Question
		for(AbstractToken abstractToken : abstractQuestion){
			abstractToken.clearInstantiationReferences();
		}
		
		// Problem Solution
		for(AbstractToken abstractToken : abstractSolution){
			abstractToken.clearInstantiationReferences();
		}
		
		// Problem EasyTip
		for(AbstractToken abstractToken : abstractEasyTip){
			abstractToken.clearInstantiationReferences();
		}
	}

}
